package com.sa.user.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.sa.user.api.dto.InstructorDTO;
import com.sa.user.dataobject.Instructor;
import com.sa.user.msmapper.MsInstructorMapper;
import com.sa.user.service.InstructorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Architecture Station
 * @version 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/instructors")
@Slf4j
public class InstructorController {
    private final InstructorService instructorService;
    private final MsInstructorMapper msInstructorMapper;


    @GetMapping("/{instructorId}")
    @SentinelResource(value = "getInstructorById")
    public ResponseEntity<InstructorDTO> getInstructorById(@PathVariable Integer instructorId ){
        log.info("收到获取讲师信息的请求，讲师ID：{}", instructorId);
        Instructor instructor = instructorService.getById(instructorId);
        if(instructor==null){
            log.warn("未找到讲师信息，讲师ID：{}", instructorId);
            return ResponseEntity.notFound().build();
        }
        InstructorDTO instructorDTO = msInstructorMapper.toDTO(instructor);
        log.info("成功获取讲师信息，讲师ID：{}", instructorId);
        return ResponseEntity.ok(instructorDTO);
    }


}
